﻿using MediatR;
using StoreIGet.Applications.Command;
using StoreIModels;
using StoreRepositorys.Interface;

namespace StoreIGet.Applications.CommandHandler
{
    public class SystematicShowCommandHandler : IRequestHandler<SystematicShowCommand, List<SystematicModel>>
    {
        public readonly ISystematicRepository _systematicRepository;
        public SystematicShowCommandHandler(ISystematicRepository systematicRepository)
        {
            _systematicRepository = systematicRepository;
        }
        public async Task<List<SystematicModel>> Handle(SystematicShowCommand request, CancellationToken cancellationToken)
        {
            var list = await _systematicRepository.GetAllasync();
            list.OrderByDescending(x => x.Systematicsort).ToList();
            var systematicCount = list.Count();
            foreach (var systematic in list)
            {
                systematic.SystematicNumber = systematicCount++;
            }
            return list;
        }
    }
}
